// pages/choseAddress/choseAddress.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    display: "none",
    _num:0,
    num:0,
    isShow:false,
    number:1,
    xian:"",
    area:'',
    city:''
  },
  show_payment: function (e) {
    console.log(e)
    if(e.currentTarget.dataset.isshow == false){
      this.setData({
        display: "block",
        isShow:true
      })
    }
    else{
      this.setData({
        display: "none",
        isShow: false
      })
    }  
  },
  hideview: function () {
    this.setData({
      display: "none"
    })
  },
  focus_click: function (e) {
    this.setData({
      _num: e.target.dataset.num,
    });
    var that=this;
    wx.request({
      url: app.data.Url +'system/getComm',
      data:{
        area: e.currentTarget.id
      },
      success:function(res){
        console.log(res.data.data)
        // return false;
        that.setData({
          shequ: res.data.data
        })
        // wx.setStorageSync("comyid",res.data.id)
      }
    })
  },
  focusClick: function (e) {
    console.log(e.target.dataset.num,'---------')
    this.setData({
      num: e.target.dataset.num,
      city: e.target.dataset.name
    });
    var that=this;
    wx.request({
      url: app.data.Url + 'system/getRegion',
      data:{
        pid: e.currentTarget.id,
        type: 3
      },
      method:'get',
      success:function(res){
        console.log(res.data)
          that.setData({
            xian: res.data
          })
      }
    })
    
  },
  chose_this: function (e) {
    app.data.address.id = e.currentTarget.id
    app.data.address.name = e.target.dataset.name
    wx.switchTab({
      url: '../index/index'
    })
    return false;
    wx.request({
      url: 'https://zhapp.4hl.cn/app/User/App_UserCommunity',
      data: {
        type: 1,
        uid: wx.getStorageSync("userInfo").uid,
        comyid: e.currentTarget.id
      },
      method: 'post',
      success: function (resdfd) {
        console.log(resdfd)
        wx.setStorageSync("dfd", resdfd.data.msg.name)
      }
    })
    
    // return false;
    
    this.setData({
      number: e.target.dataset.num
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that=this;
      
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    console.log(app.data.address)
    wx.request({
      url: app.data.Url + 'system/getRegion',
      data: {
        pid: 24,
        type: 2
      },
      method: 'get',
      success: function (res) {
        console.log(res.data)
        that.setData({
          area: res.data,
          city: res.data[0].name
        })
        wx.request({
          url: app.data.Url + 'system/getRegion',
          data: {
            pid: that.data.area[0].id,
            type: 3
          },
          method: 'get',
          success: function (res) {
            console.log(res.data,'xian')
            that.setData({
              xian: res.data
            })
            wx.request({
              url: app.data.Url + 'system/getComm',
              data: {
                area: that.data.xian[0].id
              },
              success: function (res) {
                console.log(res.data.data)
                that.setData({
                  shequ: res.data.data
                })
              }
            })
          }
        })
      }
    })
    return false;
    wx.request({
      url: app.data.Url + 'system/getRegion',
      data: {
        pid: e.currentTarget.id,
        type: 3
      },
      method: 'get',
      success: function (res) {
        console.log(res.data)
        that.setData({
          xian: res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})